package com.tubruk.database;

import java.util.ArrayList;

import com.tubruk.object.ConstantList;
import com.tubruk.object.IOption;

import android.content.Context;
import android.database.Cursor;

public class ConstantListDB {
	
	public static ArrayList<ConstantList> getByConstantId(int constantId){
		ArrayList<ConstantList> result = null;

		DatabaseHelper db = null;
		try {
			db = new DatabaseHelper();
			//String[] selectionArgs = {Integer.toString(constantId)};
			
			Cursor c = db.query(DatabaseHelper.TABLE_CONSTANT_LIST.TABLENAME, null, DatabaseHelper.TABLE_CONSTANT_LIST.CONSTANT_ID + "=" + constantId, null, "_id asc");
	
			if (c != null){
				result = new ArrayList<ConstantList>();
				if (c.moveToFirst()){
					do {
						result.add(convertDBToConstant(c));
					}while (c.moveToNext());
				}
			}
		}finally {
			if (db != null) {
				db.destroy();
			}
		}
		return result;
	}
	
	private static ConstantList convertDBToConstant(Cursor c){
		ConstantList result = new ConstantList();
		
		result.setId(c.getInt(c.getColumnIndex(DatabaseHelper.TABLE_CONSTANT_LIST.ID)));
		result.setConstantId(c.getInt(c.getColumnIndex(DatabaseHelper.TABLE_CONSTANT_LIST.CONSTANT_ID)));
		result.setTitle(c.getString(c.getColumnIndex(DatabaseHelper.TABLE_CONSTANT_LIST.TITLE)));
		
		return result;
	}

}
